from pydub import AudioSegment
from pydub.playback import play
from multiprocessing import Process
 
def play_sound(path = '/home/ninetripod/catkin_ws/src/uav/resource/audio/deliver1.mp3', amp = 0):
    def _play():
        song = AudioSegment.from_mp3(path)
        louder = song + amp

        play(louder)

    p = Process(target = _play)
    p.start()


def play_audios(audios, amp = 0):
    def _play():
        for audio in audios:
            song = AudioSegment.from_mp3(audio)
            louder = song + amp
            play(louder)

    p = Process(target = _play)
    p.start()


def play_target_audio(target):
    color = target[0]
    shape = int(target[1])

    audios = [
        "/home/ninetripod/catkin_ws/src/uav/resource/audio/detected.mp3"
    ]

    if color == "b":
        audios.append("/home/ninetripod/catkin_ws/src/uav/resource/audio/blue.mp3")
    elif color == "r":
        audios.append("/home/ninetripod/catkin_ws/src/uav/resource/audio/red.mp3")

    if shape == 0:
        audios.append("/home/ninetripod/catkin_ws/src/uav/resource/audio/circle.mp3")
    elif shape == 3:
        audios.append("/home/ninetripod/catkin_ws/src/uav/resource/audio/triangle.mp3")
    elif shape == 4:
        audios.append("/home/ninetripod/catkin_ws/src/uav/resource/audio/square.mp3")

    play_audios(audios, amp = 10)


# play_target_audio("b0")
# play_target_audio("r0")
# play_target_audio("b3")
# play_target_audio("r3")
# play_target_audio("b4")
# play_target_audio("r4")

# play_sound(amp = 10)
